package cn.scau.server.service.impl;

import cn.scau.server.pojo.Admin;
import cn.scau.server.mapper.AdminMapper;
import cn.scau.server.service.AdminService;
import cn.scau.server.vo.ResultVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 代码不跑我先跑
 * @since 2025-03-30
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    // 根据管理员id查找管理员姓名
    public ResultVO getAdminNameById(Integer id){
        // 根据消息id查找消息
        QueryWrapper<Admin> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", id);
        Admin admin = adminMapper.selectOne(queryWrapper);
        if (admin == null) {
            return ResultVO.fail("管理员不存在");
        }
        return ResultVO.success("查找成功", admin.getAdminName());
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    //根据管理员account查找管理员id
    public ResultVO getAdminIdByAccount(String account){
        QueryWrapper<Admin> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("account", account);
        Admin admin = adminMapper.selectOne(queryWrapper);
        if (admin == null) {
            return ResultVO.fail("管理员不存在");
        }
        return ResultVO.success("查找成功", admin.getId());
    }

}
